package com.jayam.gas.server;

import java.util.ArrayList;
import java.util.List;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.GrantedAuthorityImpl;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;

public class UserDetailsServiceImpl implements UserDetailsService {

	private static final String QUALITAS_ROLE_USER = "ROLE_USER";

	@Override
	public UserDetails loadUserByUsername(final String username) {
		final List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
		authorities.add(new GrantedAuthorityImpl(UserDetailsServiceImpl.QUALITAS_ROLE_USER));

		// password cannot be null or empty, otherwise there is
		// IllegalArgumentException thrown
		final User user = new User(username, "[PROTECTED]", true, true, true, true, authorities);
		return user;
	}
}
